/*
 * gx_rbtree.h
 *
 *  Created on: 2012-3-11
 *      Author: zhangguanxing
 *      Description:
 */

#ifndef GX_RBTREE_H_
#define GX_RBTREE_H_

#include "gx.h"

typedef void (*depcpy_func)(gx_rbtree_node_t *, gx_rbtree_node_t*);
typedef int (*depcmp_func)(gx_rbtree_key_t, gx_rbtree_key_t);

struct gx_rbtree_node_s {
	gx_rbtree_key_t key;
	void*			usr_data;
};

struct gx_rbtree_s {
	gx_rbtree_node_t* root;
	gx_rbtree_node_t* sentinel;

	int size;
};

int gx_rbtree_init(gx_rbtree_t* tree);
int gx_rbtree_insert(gx_rbtree_t* tree, gx_rbtree_key_t key, void* usr_data);
int gx_rbtree_delete(gx_rbtree_t* tree, gx_rbtree_node_t* node);
int gx_rbtree_search(gx_rbtree_t* tree, gx_rbtree_key_t key, gx_array_t* node_list);
int gx_rbtree_check(gx_rbtree_t* tree);
int gx_rbtree_minimum(gx_rbtree_t* tree, gx_array_t* node_list);
void gx_rbtree_destroy(gx_rbtree_t* tree);

//used only for hashring
int gx_rbtree_search_nearest(gx_rbtree_t* tree, gx_rbtree_key_t key, gx_array_t* node_list);


gx_uint32_t gx_rbtree_get_size(gx_rbtree_t* tree);

void print_rbtree(gx_rbtree_t* tree);

#endif /* gx_RBTREE_H_ */
